package com.greenantmall.bean;

import java.util.ArrayList;
import java.util.List;

import com.avos.avoscloud.AVACL;
import com.avos.avoscloud.AVClassName;
import com.avos.avoscloud.AVRole;

@AVClassName(AntAVObject.CLASS_BANNERS)
public class Banners extends AntAVObject {
		
	public static final String ATTR_USRID ="usrId";

	public static final String ATTR_FILE_URL ="image";
	
	public static final String ATTR_UPTOWNS = "uptowns";//服务区
	public static final String ATTR_LIST = "list";//服务区

	
	private AVRole customRole;
	private List<Goods> goodsList;

	public Banners() {
		super();			
		setAccessCtrl();
	}
	
	public Banners(String str) {
		super(str);
		setAccessCtrl();		
	}

	
	public String getFileUrl()
	{
		try {
			return this.getAVFile(ATTR_FILE_URL).getUrl();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	public void setFileUrl(String url)
	{
	    this.put(ATTR_FILE_URL,url);
	}
	
	
	public Banners getInstance()
	{
		return this;
	}
	public String getUserId() {
		return this.getString(ATTR_USRID);
	}

	public void setUserId(String userId) {
		this.put(ATTR_USRID,userId);
	}
	

	
	private int setAccessCtrl() {
		
		acl = new AVACL();
		acl.setPublicReadAccess(true);//�˴����õ��������˵Ŀɶ�Ȩ��
		acl.setPublicWriteAccess(true);
		this.setACL(acl);
//		acl.setReadAccess(AVUser.getCurrentUser(), true);
//		acl.setWriteAccess(AVUser.getCurrentUser(), true);//�������������ļ������ߵ�дȨ��
//		
//		this.setUserId(AVUser.getCurrentUser().getObjectId());
//		AVQuery<AVRole> query = new AVQuery<AVRole>("_Role");
//		query.whereEqualTo("name", "custom");
//		query.findInBackground(new FindCallback<AVRole>() {
//			@Override
//		    public void done(List<AVRole> avObjects, AVException e) {
//		        if (e == null) {
//		            Log.d("�ɹ�", "��ѯ��" + avObjects.size() + " ����������������");
//		            customRole=(AVRole)avObjects.get(0);   
//		            acl.setRoleReadAccess(customRole,true);
//		            getInstance().setACL(acl);
//		            
//		        } else {
//		            Log.d("ʧ��", "��ѯ����: " + e.getMessage());
//		            //acl.setPublicReadAccess(true);//�˴����õ��������˵Ŀɶ�Ȩ��
//		        }
//		    }			
//		
//		});
		return 0;
	}

	public List<Goods> getGoodsList() {
		if(goodsList==null)
		{
			goodsList=new ArrayList<Goods>();
		}
		return goodsList;
	}

	public void setGoodsList(List<Goods> goodsList) {
		this.goodsList = goodsList;
	}
	
}
